package com.leetroll.media.temp;

import com.leetroll.common.utils.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class FolderUtilForTest {

    public static void main(String[] args) throws IOException {
        copy();
    }

    private static void copy() throws IOException {
        String srcPath = "F:\\_resources\\3d_model\\BigMediumSmall\\BigMediumSmall - Medieval Collection";
        String targetPath = "F:\\_resources\\3d_model\\BigMediumSmall\\入库\\2024-3-28-db-no_zip\\Medieval Collection\\#seperate\\";

        File folder = new File(srcPath);
        File[] subFolders = folder.listFiles();
        for (File subFolder : Objects.requireNonNull(subFolders)) {
            if (!subFolder.isDirectory()) continue;
            String foldName = subFolder.getName();
            List<File> copyFiles = new ArrayList<>();
            File[] mainFiles = subFolder.listFiles();
            for (File mainFile : Objects.requireNonNull(mainFiles)) {
                if (!mainFile.getName().endsWith("png")) continue;
                copyFiles.add(mainFile);
            }
            String tgPrevPath = targetPath + foldName + "\\prev\\";
            String tgMainPath = targetPath + foldName + "\\main\\";
            File targetPrevFolder = new File(tgPrevPath);
            File targetMainFolder = new File(tgMainPath);
            if (!targetPrevFolder.exists()) {
                targetPrevFolder.mkdirs();
            }
            if (!targetMainFolder.exists()) {
                targetMainFolder.mkdirs();
            }
            for (File copyFile : copyFiles) {
                if (copyFile.getName().contains("wire")) {
                    FileUtils.copyFile(copyFile.getAbsolutePath(), tgPrevPath + copyFile.getName());
                } else {
                    FileUtils.copyFile(copyFile.getAbsolutePath(), tgMainPath + copyFile.getName());
                    FileUtils.copyFile(copyFile.getAbsolutePath(), tgPrevPath + copyFile.getName());
                }
                System.out.println("finished!");
            }
        }
    }

}
